package com.zhj.process.controller;


import com.zhj.process.common.valida.Update;
import com.zhj.process.entity.dto.ModelDTO;
import com.zhj.process.entity.req.ModelReq;
import com.zhj.process.service.ModelService;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import javax.validation.groups.Default;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

/**
 * 流程模型信息表(Model)表控制层
 *
 * @author zhonghaijun
 * @since 2023-07-06 11:36:30
 */
@RestController
@RequestMapping("/model")
@AllArgsConstructor
@Api(tags = "流程模型信息表")
public class ModelController {
    /**
     * 服务对象
     */
    private final ModelService modelService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @ApiOperation("根据Id查询")
    public ModelDTO getModelById(@PathVariable Long id) {
        Object a = null;
        a.toString();
        return this.modelService.getById(id);
    }

    /**
     * 查询所有数据
     *
     * @return list
     */
    @GetMapping("/list")
    @ApiOperation("查询Model所有数据")
    public List<ModelDTO> getModelList() {
        return this.modelService.getAll();
    }

    /**
     * 新增数据
     * Validated 只校验默认，不校验自定义
     *
     * @param modelReq 实体对象
     * @return 新增结果
     */
    @PostMapping("/save")
    @ApiOperation("保存Model")
    public Boolean saveModel(@RequestBody @Validated(value = {Default.class}) ModelReq modelReq) {
        return this.modelService.save(modelReq);
    }

    /**
     * 修改数据
     * Validated 注解校验默认和自定义的Update分组的数据
     *
     * @param modelReq 实体对象
     * @return 修改结果
     */
    @PostMapping("/update")
    @ApiOperation("修改Model")
    public Boolean updateModel(@RequestBody @Validated(value = {Default.class, Update.class}) ModelReq modelReq) {
        return this.modelService.updateById(modelReq);
    }

    /**
     * 删除数据
     *
     * @param id 主键id
     * @return 删除结果
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除")
    public Boolean deleteModelById(@PathVariable("id") Long id) {
        return this.modelService.deleteById(id);
    }
}

